﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcs.Web.Admin.instore
{
    public partial class Listtb :Web.Admin.BasePage
    {
        lcs.BLL.instore bll = new lcs.BLL.instore();
        private decimal totalAllPrice = 0;
        public string dogid = "NO";
        public string Decode(string str)
        {

            if (dogid == "NO")
            {
                if (Request.Cookies["dogid"]!=null)
                    dogid = Request.Cookies["dogid"].Value.ToString();
            }
            return DecodeDog(str, dogid);

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindData();
                Page.DataBind();
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }        
       

        public void BindData()
        { 
            if (txtgys.Text.Trim() != "")
            {
            DataSet ds = new DataSet();
            StringBuilder strWhere = new StringBuilder();
            if (txtKeyword.Text.Trim() != "")
            {
                strWhere.AppendFormat(" and cast(CONVERT(varchar(12),intime, 111) as datetime)" + ddldate.SelectedValue + " '{0}'", txtKeyword.Text.Trim());
            }            
            
                strWhere.AppendFormat(" and supplier like '%{0}%'", txtgys.Text.Trim());
                       
            if (Session["login"] != null)
            {
                DataSet u = (DataSet)Session["login"];

                if (u.Tables[0].Rows[0]["roles_id"].ToString() == "2")
                {
                    strWhere.AppendFormat(" and uid={0}", u.Tables[0].Rows[0]["user_id"]);
                }
            }
            ds = bll.GetinstoreByWhere(strWhere.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                lbl_time.Text = ds.Tables[0].Rows[0]["intime"].ToString();
                lblstore.Text = ds.Tables[0].Rows[0]["sname"].ToString();
                lblsupplier.Text = ds.Tables[0].Rows[0]["supplier"].ToString();
            }
            gridView.DataSource = ds;
            gridView.DataBind();
            
            } 
        }

       
        protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            e.Row.Attributes.Add("style", "background:#FFF");
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lbl_unprice = e.Row.FindControl("lbl_unprice") as Label;//单价
                Label lbl_totalPrice = e.Row.FindControl("lbl_totalPrice") as Label;//金额
                Label lbl_nums = e.Row.FindControl("lbl_nums") as Label;//数量

                decimal unprice = decimal.Parse(lbl_unprice.Text);

                lbl_unprice.Text = unprice.ToString("0.00");

                decimal nums = decimal.Parse(lbl_nums.Text);

                lbl_totalPrice.Text = (unprice * nums).ToString("0.00");

                totalAllPrice += unprice * nums;
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                Label lbl_totalAllPrice = e.Row.FindControl("lbl_totalAllPrice") as Label;//总计金额

                lbl_totalAllPrice.Text =  totalAllPrice.ToString("0.00");
            }
        }
       
    }
}